import { defHttp } from '/@/utils/http/axios';
import { Modal } from 'ant-design-vue';
import { stringFormat } from '/@/utils/common/compUtils';

enum Api {
  list = '/api-workflow/wf/processDefine/list',
  get = '/api-workflow/wf/processDefine/detail',
  delete = '/api-workflow/wf/processDefine/delete',
  deleteBatch = '/api-workflow/wf/processDefine/deleteBatch',
  upAndDown = '/api-workflow/wf/processDefine/upAndDown',
  startAndExecute = '/api-workflow/wf/processDefine/startAndExecute',
  exportXls = '/api-workflow/wf/processDefine/export',
  importExcel = '/api-workflow/wf/processDefine/import',
}

/**
 * 导出api
 */
export const getExportUrl = Api.exportXls;

export const getImportUrl = Api.importExcel;

/**
 * 分页查询流程设计列表
 * @param params 查询参数
 * @returns
 */
export const list = (params) => defHttp.get({ url: Api.list, params });

/**
 * 获取流程定义详情
 * @param params 查询参数
 * @returns
 */
export const getProcessDefineById = (params) => {
  return defHttp.get({ url: Api.get, params });
};

/**
 * 单条删除流程设计
 * @param params
 */
export const deleteProcessDefine = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.delete, data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 批量删除流程设计
 * @param params
 */
export const batchDeleteProcessDefine = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};

/**
 * 启用/禁用流程定义
 * @param params
 * @returns
 */
export function upAndDownProcessDefine(params) {
  return defHttp.post({ url: Api.upAndDown, params });
}

/**
 * 发起流程
 * @param params
 * @returns
 */
export function startAndExecuteProcessDefine(params) {
  return defHttp.post({ url: Api.startAndExecute, params });
}
